Row

Data Skim

Data summary
Name Piped data
Number of rows 66113
Number of columns 16
_______________________
Column type frequency:
character 6
logical 2
numeric 8
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
state 0 1.00 4 14 0 32 0
year 0 1.00 4 7 0 4 0
name 0 1.00 1 91 0 36129 0
type 36622 0.45 5 12 0 6 0
city 20071 0.70 2 43 0 5665 0
county 6254 0.91 3 21 0 1158 0

Variable type: logical

skim_variable n_missing complete_rate mean count
district 66113 0 NaN :
xrel 66004 0 1 TRU: 109

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
index 0 1.00 1607.69 1706.77 1.00 429.00 997.00 2133.00 8066.00 ▇▂▁▁▁
enroll 16260 0.75 131.93 162.16 0.00 46.00 80.00 129.00 6222.00 ▇▁▁▁▁
mmr 0 1.00 63.17 45.72 -1.00 -1.00 95.00 98.00 100.00 ▅▁▁▁▇
overall 0 1.00 54.09 46.67 -1.00 -1.00 87.00 96.10 100.00 ▆▁▁▁▇
xmed 45122 0.32 2.91 3.85 0.04 1.00 2.00 3.53 100.00 ▇▁▁▁▁
xper 57560 0.13 6.78 7.62 0.17 2.84 5.00 7.55 169.23 ▇▁▁▁▁
lat 1549 0.98 39.15 4.58 24.55 35.69 40.21 42.18 49.00 ▁▃▅▇▂
lng 1549 0.98 -96.28 18.44 -124.50 -117.63 -89.97 -81.75 80.21 ▇▃▁▁▁

Data Table

Row

Map

Density plot

---
title: "Flexdashboard Measles"
output: 
  flexdashboard::flex_dashboard:
    theme: paper
    orientation: rows
    vertical_layout: fill
    source_code: embed
---

```{r, include = FALSE}
library(ggplot2)
library(tidyverse)
library(skimr)
library(flexdashboard)
library(DT)
library(leaflet)
library(crosstalk)
library(maps)
library(plotly)

measles <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-02-25/measles.csv')
measles_df<- measles %>% 
  filter(state== "Massachusetts") %>%
  filter(city %in% c("Cambridge", "Boston", "Brookline", "Chestnut Hill", "Dorchester", "East Boston", "Jamaica Plain", "Malden", "Newton", "Newton Center", "Roxbury", "South Boston", "Watertown", "West Newton", "West Roxbury")) %>%
  filter(type %in% c("Public", "Charter", "Private")) %>% 
  select(-district, -overall, -xrel, -xmed, -xper, -index)

shared_df <- SharedData$new(measles_df)
```

Row 
-------------------------------------

### Data Skim

```{r table}
measles %>% 
  skim()
```

### Data Table {.tabset .tabset-fade}

```{r table1}
DT::datatable(shared_df, filter = "top",  # allows filtering on each column
    extensions = c(
      "Buttons",  # add download buttons, etc
      "Scroller"  # for scrolling down the rows rather than pagination
    ),
    rownames = FALSE,  # remove rownames
    style = "bootstrap",
    class = "compact",
    width = "100%",
    options = list(
      dom = "Blrtip",  # specify content (search box, etc)
      deferRender = TRUE,
      scrollY = 300,
      scroller = TRUE,
      columnDefs = list(
        list(
          visible = FALSE,
          targets = c(8:9)
        )
      ), 
      buttons = list(
        I("colvis"),  # turn columns on and off
        "csv",  # download as .csv
        "excel"  # download as .xlsx
      )
    ) )
```


Row 
-------------------------------------
### Map

```{r map}
mapStates <- map("state", fill = TRUE, plot = FALSE)

leaflet(data = mapStates) %>% 
  addProviderTiles(providers$CartoDB.Positron) %>%
  addCircleMarkers(data = shared_df, color = c("blue", "red", "orange"), fillColor = "type") %>%
  addMeasure()
```

### Density plot
```{r plot1}
g<- ggplot(shared_df, aes(mmr, fill = type), alpha=0.5) +
  geom_density() +
  facet_grid(year~.) +
  scale_fill_manual(values = c("blue", "red", "orange")) + 
  theme(legend.position="bottom")

ggplotly(g) %>% 
  layout(legend = list(orientation = "h", x = 0.4, y = -0.2)) %>%
  highlight("plotly_selected")

```